---
title: "Conditions"
---

# Conditions

Attach a condition to any step or action to decide at runtime whether it should run. A condition is a mustache expression that can reference outputs from earlier steps, workflow variables, or any other data in the execution context.

Using conditions, you can introduce decision-making into workflows by asserting values, thresholds, or specific states.

### Simple `if` condition

```yaml
actions:
  - name: notify-slack
    if: "{{ alert.cpu_load }} == '70'"
    provider:
      type: slack
      config: "{{ providers.slack }}"
      with:
        message: "The CPU load exceeded the threshold!"
```

<Warning>
  **Values of variables will be quoted when evaluated**. For example, if
  `alert.cpu_load` is `70`, it will resolve to `'70'` (number quoted with single
  quotes).
</Warning>

### Using results of other steps in condition

```yaml
workflow:
  id: query-and-alert
  description: "Query a database and notify only if a threshold is met"
  steps:
    - name: get-disk-usage
      provider:
        type: mysql
        config: "{{ providers.mysql-prod }}"
        with:
          query: "SELECT disk_usage FROM metrics WHERE server = 'db1'"
          single_row: true

  actions:
    - name: notify-slack
      if: "{{ steps.get-disk-usage.results.disk_usage }} > 90"
      provider:
        type: slack
        config: "{{ providers.slack }}"
      with:
        message: "Disk usage is critical: {{ steps.get-disk-usage.results.disk_usage }}%"
```

### Complex logic

```yaml
actions:
  - name: create-incident
    if: "{{ steps.get-alert.results.severity }} == 'critical' and {{ steps.get-alert.results.source }} == 'datadog'"
    provider:
      type: servicenow
      config: "{{ providers.servicenow }}"
      with:
        table_name: INCIDENT
        payload:
          short_description: "Critical Datadog alert received"
```

### Condition with foreach

```yaml
actions:
  - name: process-pods
    foreach: "{{ steps.get-pods.results }}"
    if: "{{ foreach.value.status.phase }} == 'Failed'"
    provider:
      type: slack
      with:
        message: "Pod {{ foreach.value.metadata.name }} has failed!"
```

## Condition with constants

```yaml
consts:
  max_load: 70
actions:
  - name: process-pods
    if: "{{ alert.cpu_load }} > {{ consts.max_load }}"
    provider:
      type: slack
      with:
        message: "Pod {{ foreach.value.metadata.name }} has failed!"
```

---

## Explicit condition blocks (deprecated)

<Warning>
  Explicit condition blocks are deprecated and will be discontinued. Use the
  `if` syntax instead.
</Warning>

### assert (deprecated)

Checks whether a specific assertion is true.

```yaml
condition:
  - name: assert-condition
    type: assert
    assert: "{{ steps.get-data.results.value }} == 'expected'"
```

### threshold (deprecated)

Compares a value to a threshold using operators like `>` (gt) and `<` (lt), defaults to `>` (gt).

```yaml
condition:
  - name: threshold-condition
    type: threshold
    value: "{{ steps.get-data.results.value }}"
    compare_to: 100
    compare_type: gt
```
